<?php
/**
 * Component Model.
 * @package    sitrack 
 * @author     Simon Downes <simon@simondownes.co.uk>
 * @copyright  Copyright (c) 2007, Simon Downes 
 * @license    http://www.opensource.org/licenses/mit-license.php
 */

/**
 * Component Model.
 *
 * @package    sitrack 
 * @author     Simon Downes <simon@simondownes.co.uk>
 * @copyright  Copyright (c) 2007, Simon Downes 
 * @license    http://www.opensource.org/licenses/mit-license.php
 */
final class Component extends SPF_Model {

   /**
    * Constructor.
    *
    * @return  object
    */
   public function __construct() {

      /* construct the parent object */
      parent::__construct('components');
      
      $this->add_validation('description', true, 'custom');
      
   } // __construct

   /**
    * Destructor.
    *
    * @return  void
    */
   public function __destruct() {
      parent::__destruct();
   }
   
   /**
    * Override the clear() method to ensure the active field is defaulted to 1.
    *
    * @param   boolean   $keep_id   if true the primary key fields will not be cleared.
    * @return  void
    */
   public function clear( $keep_id = false ) {
       
       parent::clear($keep_id);
       
       $this->active = 1;
       
   } // clear
   
   /**
    * Override the after_delete() method to clear the component_id field of tickets with the component_id we're deleting.
    *
    * @param   array     $args   primary key values of the record.
    * @return  boolean
    */
   public function after_delete( $args ) {
      
      $id = (int) array_shift($args);
      
      $this->db->update_field('tickets', 'component_id', 0, "component_id = {$id}");
      
   } // after_delete
   
} // Component

?>
